package cn.ywang.framework;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Auther: BeatificWang
 * @Date: 2018/11/17 17:01
 */
public class MapperProxy implements InvocationHandler {

	private SqlSession sqlSession;

	public MapperProxy(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		// 如果方法所属类与XML类中类名相等
		if (method.getDeclaringClass().getCanonicalName().equals(Configuration.MemberMapperXML.namespace)) {
			String sql = Configuration.MemberMapperXML.methodSql.get(method.getName());
			return this.sqlSession.selectOne(sql, String.valueOf(args[0]));
		}
		return method.invoke(this, args);
	}
}
